package leetcode_2501_2600;

import java.util.Arrays;
import java.util.Comparator;

public class LeeCode_2560 {
    public static void main(String[] args) {

    }
    private static int minCapability(int[] nums, int k) {
        int n = nums.length;
        int l = 0, r = (int) 1e9;
        while (l + 1 < r){
            int m = (l + r) >>> 1;
            int f0 = 0, f1 = 0;
            for (int num : nums) {
                if (num > m){
                    f0 = f1;
                }else {
                    int tmp = f1;
                    f1 = Math.max(f0 + 1, f1);
                    f0 = tmp;
                }
            }
            if (f1 >= k){
                r = m;
            }else {
                l = m;
            }
        }
        return r;
    }
}
